package com.shy.treadsafe;

import java.util.concurrent.TimeUnit;

public class AccountService {
    private Integer balance = 1000;

    public void add(Integer money) {
        Integer newMoney = balance + money;

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        balance = newMoney;
    }

    public void del(Integer money) {
        Integer newMoney = balance - money;

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        balance = newMoney;
    }

    public Integer getBalance() {
        return balance;
    }

}
